#ifndef BM8563_H
#define BM8563_H

#include "stdint.h"
#include "stddef.h"
#include "driver/gpio.h"
#include "driver/i2c_master.h"
#include "esp_log.h"
#include "esp_check.h"

#define BM8563_I2C_ADDR   0x51

/* Register map start */
#define BM8563_CTRL1      0x00U
#define BM8563_CTRL2      0x01U

#define BM8563_SEC        0x02U
#define BM8563_MIN        0x03U
#define BM8563_HOUR       0x04U
#define BM8563_DAY        0x05U
#define BM8563_WEEK       0x06U
#define BM8563_MONTH      0x07U
#define BM8563_YEAR       0x08U
#define BM8563_MIN_ALARM  0x09U
#define BM8563_HOUR_ALARM 0x0AU
#define BM8563_DAY_ALARM  0x0BU
#define BM8563_WEEK_ALARM 0x0CU

#define BM8563_CLKOUT     0x0DU
#define BM8563_TIM_CTRL   0x0EU
#define BM8563_TIM_VAL    0x0FU
/* Register map end */

typedef enum
{
    BM8563_FCLKOUT_32K768HZ = 0,
    BM8563_FCLKOUT_1024HZ   = 1,
    BM8563_FCLKOUT_32HZ     = 2,
    BM8563_FCLKOUT_1HZ      = 3
}BM8563_clkout_frq_t;

typedef struct
{
    bool int_state;
    BM8563_clkout_frq_t frequency;
}BM8563_clkout_t;

typedef enum
{
    BM8563_FTIMER_4096HZ = 0,
    BM8563_FTIMER_64HZ   = 1,
    BM8563_FTIMER_1HZ    = 2,
    BM8563_FTIMER_1HZ60  = 3
}BM8563_timer_frq_t;

typedef struct
{
    bool int_state;
    BM8563_timer_frq_t frequency;
}BM8563_timer_t;

typedef struct
{
    uint32_t          SCL_Speed;
    uint8_t           Addr;
    uint8_t           is_initialized;
    BM8563_clkout_t   clockout;
    BM8563_timer_t    timer;
}BM8563_Object_t;

typedef struct
{
    uint8_t second;
    uint8_t minute;
    uint8_t hour;
    uint8_t day;
    uint8_t week;
    uint8_t century;
    uint8_t month;
    uint8_t year;
}BM8563_Data_t;

esp_err_t bm8563_set_time();
esp_err_t bm8563_get_time();

esp_err_t bm8563_set_alarm();
esp_err_t bm8563_set_countdown();


#endif
